using UnityEngine;

public class PlayerAIState_Defense_HelpDefense : State<PlayerAI>
{
	public static PlayerAIState_Defense_HelpDefense instance;

	private PlayerAIState_Defense_HelpDefense()
	{
	}

	public static PlayerAIState_Defense_HelpDefense getInstance()
	{
		if (instance == null)
		{
			instance = new PlayerAIState_Defense_HelpDefense();
		}
		return instance;
	}

	public override void enter(PlayerAI owner)
	{
		base.enter(owner);
	}

	public override void fixedUpdate(PlayerAI owner)
	{
		base.fixedUpdate(owner);
		helpDefense(owner);
	}

	public override void exit(PlayerAI owner)
	{
		base.exit(owner);
	}

	private void helpDefense(PlayerAI owner)
	{
		if (owner.time_Stop > 0f)
		{
			owner.time_Stop -= Time.fixedDeltaTime;
			return;
		}
		if (owner.player.getParaTeam().IsAnyOneControlBall() && MathHelper.getSqrDistance(owner.player.getParaTeam().getPlayer_ControlBall().paraPlayer.getPosition(), owner.player.getPosition()) < 2f)
		{
			owner.time_Stop = 0f;
			owner.do_defense_defense();
			return;
		}
		if (owner.player.getParaTeam().IsAnyOneControlBall())
		{
			owner.player.LookAt(owner.player.getParaTeam().getPlayer_ControlBall().getPosition());
			owner.defense_defense_pos_target = DSS.GetDefensePos(MathHelper.setY(owner.player.getParaTeam().getPlayer_ControlBall().getPosition(), 0f), owner.player.getOffenseDirection() == OffenseDirection.RIGHT);
		}
		if (!GameHelper.MoveTo(owner.player, owner.defense_defense_pos_target, owner.player.getMoveSpeed(), isLookAtTargetPos: true))
		{
			owner.player.do_run();
			return;
		}
		owner.time_Stop = owner.player.team.time_reaction_to_defensepos;
		owner.player.do_defense();
		if (owner.player.getParaTeam().IsAnyOneControlBall())
		{
			owner.player.LookAt(owner.player.getParaTeam().getPlayer_ControlBall().getPosition());
		}
	}
}
